﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>Test</title>
    <link href="@Url.Content("~/Areas/User/Css/all2.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Areas/User/Css/shop.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/JS/jquery.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/JS/artDialog/artDialog.js?skin=chrome")" type="text/javascript"></script>
    <script src="@Url.Content("~/JS/artDialog/plugins/iframeTools.source.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/JS/artDialog/dialogHelper.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/JS/artDialog/artDialog.source.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/JS/Gallery.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/JS/swfUploadImg/swfupload.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/JS/swfUploadImg/plugins/swfupload.speed.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/JS/SYHUpload.js")" type="text/javascript"></script>
</head>
<body>
    <div>
        <a hidefocus="" href="###" onclick="openUploadView(1)">插入图片</a>
         <span class="gray fd-left ml10">建议您上传产品实拍大图，帮助买家直观了解您的产品细节</span><span
                            class="red1">（最多插入4张图片）</span> </li>
                <li style="display: none;" id="uplodeImgList">
                    <div class="pro-t fd-left">
                    </div>
                      @foreach (var single in @Model.Rows)
                      {
                            <div class="picture" id="@single["Id"]_img">
                                <span class="pclose"><a hidefocus="" href="###" onclick="DelImg('"@single["Id"]','"@single["ImageName"]',1);">
                                </a></span>
                                <img src="@Common.GDI.ResizeImage(single["ImageName"].ToString(),100) %>" />
                            </div>
                            <input type="hidden" name="img_lodingImg" value="@single["ImageName"]" imgid="@single["Id"]" />
                      }
        <input id="HidImgNames" name="HidImgNames" type="hidden" value="" />
        <input id="HidImgIDs" name="HidImgIDs" type="hidden" value="" />
    </div>
    <script type="text/javascript">
        //插入图片
        galleryDelegte.callBack = function (json) {
            var obj = eval(json);  //解析json数组为对象
            var imgList = "";
            $.each(obj,function(index,element){
                if(($(".picture").size()+index +1) > 4){
                    jQuery.dialogHelper.alert("最多上传四张图片！", "alert");  //状态包括:success,smile,alert
                    return false;
                }
                var url = element.url;  //图片url
                var array = url.split('/'); //图片url分割后的数组
                var name = array[array.length - 1].substring(0, 32); //去掉后缀的图片名
                var imgName = name + element.exteson;
                var imgNameList = $("#HidImgNames").val() + imgName + ",";
                var imgIdList = $("#HidImgIDs").val() + element.imgid + ",";
                $("#HidImgNames").val(imgNameList);  //要提交的图片名集合
                $("#HidImgIDs").val(imgIdList);  //要提交的图片编号集合
                imgList += "<div class='picture' id='"+element.imgid+"_img'><span class='pclose'><a href='###' onclick=\"DelImg('" + element.imgid + "','" + imgName + "');\" ></a></span><img src='"+element.url+"' /></div> ";
                
            });
            $("#uplodeImgList").css("display","block"); 
            $("#uplodeImgList").append(imgList);
            jQuery.dialogHelper.close("ablumid");
        }
        //删除
        function DelImg(id,name,flag){
            //从提交数据中移除要删除的图片
            $("#HidImgNames").val($("#HidImgNames").val().replace(name+",", ""));
            $("#HidImgIDs").val($("#HidImgIDs").val().replace(id+",", ""));
            //数据库中已存在的图片
            if(flag == 1){
                $.ajax({
                    type: "POST",
                    url: "/User/Images/DelImg",
                    dataType: "text",
                    data: "id=" + id + "&imgName=" + name,
                    error: function () {
                            jQuery.dialogHelper.alert("网络忙，请稍后再试", "alert");
                        },
                    success: function (msg) {
                        if (msg == "1") {
                            $("#"+id+"_img").remove();
                        } else {
                            jQuery.dialogHelper.alert("操作有误", "alert");
                        }
                    }
                });
            }else{
                $("#"+id+"_img").remove();
            }
            //没有图片则清除样式
            if($(".picture").size()<=0){
                $("#uplodeImgList").css("display","none");
            }
        }

        //页面加载事件
        $(function () {
            
            //图片样式
            if ($(".picture").size() > 0) {
                $("#uplodeImgList").css("display", "block");
            }
            //图片加载赋值
            var imgList = "";
            var imgIdList = "";
            $("input[name='img_lodingImg']").each(function (i, current) {
                imgList += $(current).val() + ",";
                imgIdList += $(current).attr("imgId") + ",";
            });
            $("#HidImgNames").val(imgList);
            $("#HidImgIDs").val(imgIdList);
        });
        </script>
</body>
</html>
